﻿using BasehInfoManagerViewModel.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BaseInfoManagerDal
{
    //封装依赖注入    封装
  public  class BaseDal
    {     
        
        //以来注入上下文
        protected ManagerDbContext _managerDbContext;
        public BaseDal(ManagerDbContext managerDbContext)
        {
            _managerDbContext = managerDbContext;
        }



        //显示分页封装
        public PagerResult<T> BasePageSearch<T>(IQueryable<T> query, SearchModel searchModel) where T : class, new()
        {
            //获取角色总行数
            int total = query.Count();
            //实例化分页封装
            PagerResult<T> result = new PagerResult<T>()
            {
                PageCount = (int)Math.Ceiling((decimal)total / searchModel.PageSize),
                //赋值给封装类的条数
                Total = total,
                Data = query.Skip(searchModel.Start).Take(searchModel.PageSize).ToList(),
                PageIndex = searchModel.PageIndex
            };
            return result;
        }
    }
}
